package collection;

import java.util.EmptyStackException;

public class MyStack<T> {
    private MyArrayList<T> arrayList;

    public MyStack() {
        arrayList = new MyArrayList<>();
    }

    public MyStack(int capacity) {
        arrayList = new MyArrayList<>(capacity);
    }

    public void push(T val) {
        arrayList.add(val);
    }

    public T peek() {
        if (arrayList.isEmpty()) {
            throw new EmptyStackException();
        }
        return (T) arrayList.get(arrayList.size() - 1);
    }

    public T pop() {
        if (arrayList.isEmpty()) {
            throw new EmptyStackException();
        }
        return (T) arrayList.remove(arrayList.size() - 1);
    }

    public boolean empty() {
        return arrayList.isEmpty();
    }
}
